#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
    int triangleNumber(vector<int>& nums) {
        //Ż
        sort(nums.begin(), nums.end());
        //˫ָ
        int value = 0;
        for (int i = nums.size() - 1; i >= 2; i--)
        {
            int left = 0, right = i - 1;
            while (left < right)
            {
                if (nums[left] + nums[right] > nums[i])
                {
                    value += right - left;
                    right--;
                }
                else
                {
                    left++;
                }
            }
        }
        return value;
    }
};
int main()
{
    vector<int> v = { 1,1,3,5,7,9,10 };
    cout << Solution().triangleNumber(v) << endl;
	return 0;
}
/*
题目链接:https://leetcode.cn/problems/valid-triangle-number/
*/